var t=require("through2");
var Path=require("path");
var fs=require("fs");

module.exports=function(dest,permission){
    if (permission==null) permission="0777";
    return t.obj(function(file,enc,_cb){
        var _this=this;
        function cb(){_this.push(file);_cb();}
        if (!file.relative) return cb();
        var path=Path.join(dest,file.relative);
        fs.exists(path,function(b) {
            if (!b) return cb();
            fs.chmod(path, permission, function () {
                cb();
            });
        });
    });
};

